<cfsetting enablecfoutputonly="Yes">

<!--- 
  /**
   * @author  rens@joxx.nl
   * @author  email@mingo.nl
   * @version 1.0 - 2003.11.12
   */
--->

<cfscript>
  /* cfparam equivalents */
  if( not isDefined( "attributes.sReturnVar" ))       { attributes.sReturnVar     = "local.aApplicationTree"; }
  
  if( not isDefined( "attributes.sStartDir" ))        { attributes.sStartDir      = request.site.s_ANCHOR_PATH & "/www"; }
  
  attributes.sStartDir = request.udf.pathFormat( attributes.sStartDir );

  // Initialize the recursion data we need to keep track of
  if( not isDefined( "request.recursion" ))           { request.recursion = structNew(); }
  if( not isDefined( "request.recursion.dirtree" ))
  {
    request.recursion.dirtree = structNew();
    
    request.recursion.dirtree.nDepth            = -1;
    request.recursion.dirtree.lIllegalDirNames  = "system";
    request.recursion.dirtree.sReturnVar        = attributes.sReturnVar;
    request.recursion.dirtree.sStartDir         = attributes.sStartDir & "/";
    request.recursion.dirtree.aApplicationTree  = arrayNew( 1 );
    
    arrayAppend( request.recursion.dirtree.aApplicationTree, "." );
  }

  request.recursion.dirtree.nDepth = request.recursion.dirtree.nDepth + 1;
</cfscript>

<cfdirectory 
  action="list" 
  directory="#attributes.sStartDir#" 
  name="qry_sel_dir"
>

<cfloop query="qry_sel_dir">

  <cfif ( type eq "dir" ) and 
        ( not listFind( request.recursion.dirtree.lIllegalDirNames, name )) and 
        ( not mid( name, 1, 1 ) eq "_" ) and
        ( not mid( name, 1, 1 ) eq "." ) and
        ( not mid( name, 1, 1 ) eq "-" ) and
        ( not mid( name, 1, 1 ) eq "@" ) and
        ( request.recursion.dirtree.nDepth lte 32 )
  >
    <cfscript>
      arrayAppend( 
                   request.recursion.dirtree.aApplicationTree, 
                   lCase( replace( "#attributes.sStartDir#/#name#", request.recursion.dirtree.sStartDir, "", "one" ))
                 );
    </cfscript>
    
    <cfmodule 
      template="#request.site.s_CFROOT#/lib/customtags/dirtree.cfm"
      sStartDir="#attributes.sStartDir#/#name#"
    >
  </cfif>
</cfloop>

<cfscript>
  request.recursion.dirtree.nDepth = request.recursion.dirtree.nDepth - 1;
  
  if( request.recursion.dirtree.nDepth eq -1 )
  {
    "caller.#attributes.sReturnVar#" = duplicate( request.recursion.dirtree.aApplicationTree );
  }
</cfscript>

<cfsetting enablecfoutputonly="No">
